package com.baitiaojun.common.enums.impl;

import cn.hutool.core.util.ArrayUtil;
import com.baitiaojun.common.enums.Enums;

import java.util.Arrays;

public enum HttpMethodEnums implements Enums {

    GET(0, "get"),
    HEAD(1, "head"),
    POST(2, "post"),
    PUT(3, "put"),
    PATCH(4, "patch"),
    DELETE(5, "delete"),
    OPTIONS(6, "options"),
    TRACE(7, "trace");

    private final Integer code;

    private final String name;

    HttpMethodEnums(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public Enums valueOf(Integer code) {
        return ArrayUtil.firstMatch(item -> item.getCode().equals(code), values());
    }

    @Override
    public int[] array() {
        return Arrays.stream(values()).mapToInt(HttpMethodEnums::getCode).toArray();
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getName() {
        return name;
    }
}
